<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!-- 代理佣金页面 -->
<section  data-v-16d172c6="" class="main-content agentCommission view">
	<div class="statistics">
		<div class='fandianje'><span>返点金额</span><em>0元</em></div>
		<div class='chongzhije'><span>充值金额</span><em>0元</em></div>
		<div class='damaje'><span>打码金额</span><em>0元</em></div>
		<div class='gofandian'><span>可领取返点</span><em>0元</em></div>
		<div class='getfandianje'><button>点击领取</button></div>
	</div>
	<div data-v-16d172c6="" class="search"><span data-v-16d172c6="">时间：</span>
		<select data-v-16d172c6="" class="select select-dateshijian">
			<option data-v-16d172c6="" value="">今天</option>
			<option data-v-16d172c6="" value="1">
				昨天
			</option>
			<option data-v-16d172c6="" value="3">
				一周
			</option>
			<option data-v-16d172c6="" value="4">
				半个月
			</option>
		</select><span data-v-16d172c6="">日期：</span>
		<div data-v-16d172c6="" class="ivu-date-picker">
			<div class="ivu-date-picker-rel">
				<div class="ivu-input-wrapper ivu-input-type ivu-date-picker-editor">
					<!----><!-- <i class="ivu-icon ivu-icon-ios-calendar-outline ivu-input-icon ivu-input-icon-normal"></i> -->
					<input type="text" id="date1" placeholder="开始时间" value="" lay-key="" class="ivu-input layer-date" readonly="readonly">
					<span style="margin: 0 10px;">至</span>
					<input type="text" id="date2" placeholder="结束时间" value="" lay-key="" class="ivu-input layer-date" readonly="readonly">		
					<!----><!-- <input autocomplete="off" spellcheck="false" type="text" placeholder="请选择修改日期" class="ivu-input"> -->
					<!---->
				</div>
			</div>
			<div class="ivu-select-dropdown" style="display: none;">
				<div></div>
			</div>
		</div> <button data-v-16d172c6="" class="button demand chaxdailyj">查询</button></div>
		<table data-v-16d172c6="" class="class-tableDataTable class-table-needClick display table table-striped table-bordered table-hover "  id="table-i-dailiList" ><!-- table  -->
			<thead data-v-16d172c6="">
				<tr data-v-16d172c6="">
					<th data-v-16d172c6="">下级账号</th>
					<th data-v-16d172c6="">下级等级</th>
					<th data-v-16d172c6="">下级余额</th>
					<th data-v-16d172c6="">充值金额</th>
					<th data-v-16d172c6="">打码金额</th>
					<th data-v-16d172c6="">返点金额</th>
				</tr>
			</thead>
			<tbody  id="div-user-message">
				<td colspan="20" style="text-align: center; padding: 20px 0px;">没有更多的数据了</td>
			</tbody>
		</table>
</section>
<script type="text/javascript">
layui.use('laydate', function() { //layui时间插件
	 laydate= layui.laydate;
	laydate.render({
		elem: '#date1'
	});
	laydate.render({
		elem: '#date2'
	});
});

$.ajax({
	type: 'post',
	url: "/agent/findAgentRebateSum.do",
	data: {
		"startDate": null,
		"endDate": null
	},
	success: function(data) {
		newData = data.data;
		$(".fandianje em").text(newData.rebate_money);
		$(".chongzhije em").text(newData.recharge_money);
		$(".damaje em").text(newData.code_money)
		$(".gofandian em").text(newData.one_money);
	}
});
var s1 = GetDateStr(0);
  $("#date1").val(s1);
 $("#date2").val(s1); 
var StartDate = $("#date1").val();
var EndDate = $("#date2").val();
$("#btn_money").on("click", function() {
	$.ajax({
		type: 'post',
		url: "/agent/receiveRebateMoney.do",
		data: {},
		success: function(data) {
			if(data.data == 2) {
				bindLayerLittle("提示：", "领取金额必须大于" + data.message)
			}
			if(data.data == 0) {
				$("#lead_money").text(data.data);
			}
		}
	});
})

function dataTable05() {
	var oTable = $("#table-i-dailiList").DataTable({
		"bProcessing": false, // 是否显示取数据时的那个等待提示
		"bServerSide": true, //这个用来指明是通过服务端来取数据
		"bPaginate": true, //是否显示分页 
		"sAjaxSource": "/agent/findAgentRebateInfo.do", //这个是请求的地址
		"fnServerData": retrieveData, // 获取数据的处理函数
		"destroy": true,
		// "bPaginate": true,
		"bLengthChange": true,
		"bSort": false,
		"dom": 't<"toolbar" pi>',
		"bInfo": true,
		"bAutoWidth": false,
		//						         "bServerSide":true,
		'aLengthMenu': [5, 10, 20],
		"searching": false,

		"pagingType": "simple_numbers",
		"autoWidth": false,
		"language": { //语言设置  
			"zeroRecords": "暂时没有数据哦",
			"sInfo": "第 _PAGE_ / _PAGES_ 页",
			"info": "没有数据",
			"oPaginate": {
				"sFirst": "首页",
				"sPrevious": "上一页",
				"sNext": "下一页",
				"sLast": "尾页"
			},
			"search": "",
			"searchPlaceholder": "请输入关键字",
			"infoFiltered": "",
			"infoEmpty": "",
		},
		"columnDefs": [{
			"defaultContent": "",
			"targets": "_all"
		}],
		"columns": [{
				"data": "user_name",
				"className": "user_name-td"
			},
			{
				"data": "agent_grade",
				"className": "agent_grade-td"
			},
			{
				"data": "balance",
				"className": "balance-td"
			},
			{
				"data": "recharge_money",
				"className": "recharge_money-td"
			},
			{
				"data": "code_money",
				"className": "code_money-td"
			},
			{
				"data": "rebate_money",
				"className": "rebate_money-td"
			},
		],
	})

	function retrieveData(sSource, aoData, fnCallback) {
		$.ajax({
			url: sSource, //这个就是请求地址对应sAjaxSource
			data: {
				"pageCount": aoData[0].value,
				"startIndex": aoData[3].value,
				"lineCount": aoData[4].value,
				"startDate": StartDate,
				"endDate": EndDate
			}, //这个是把datatable的一些基本数据传给后台,比如起始位置,每页显示的行数
			type: 'post',
			dataType: 'json',
			async: false,

			success: function(result) {
				var newData = result.aaData;
				fnCallback(result); //把返回的数据传给这个方法就可以了,datatable会自动绑定数据的
			},
			error: function(msg) {}
		});
	}
}
dataTable05()

/*领取返点金额  */
$(".getfandianje button").on("click",function(){
	$.ajax({
		type:'post',
		url:"/agent/receiveRebateMoney.do",
		data:{
		},
		success:function(data){
			if(data.data == 2){
				bindLayerLittle('提示',"领取金额必须大于"+data.message);
			}
			$(".gofandian em").text(data.data);
		},
	});
})



//代理佣金
$(".agentCommission").on("click", ".chaxdailyj", function() {
	StartDate = $("#date1").val();
	EndDate = $("#date2").val();
	console.log(StartDate, EndDate)
	if(Number(StartDate.replace(/-/g, "")) > Number(EndDate.replace(/-/g, ""))) {
		bindLayerLittle("提示：", "开始时间不能大于结束时间")
	} else {
		dataTable05()
	}
})
$(".search .select-dateshijian").on("click", function() {
	function trimStr(str) {
		var re = /^\s+|\s+$/g; // |代表或者 \s代表空格  +至少一个 前面有至少一个空格 或者后面有至少一个空格 且全局匹配
		return str.replace(re, ''); //把空格替换成空
	}
	var str = trimStr($('.select-dateshijian option:selected').text());
	if(str == "今天") {
		StartDate = GetDateStr(0)
		EndDate = GetDateStr(0)
	} else if(str == "昨天") {
		StartDate = GetDateStr(1)
		EndDate = GetDateStr(1)
	} else if(str == "一周") {
		StartDate = GetDateStr(7)
		EndDate = GetDateStr(0)
	} else {
		StartDate = GetDateStr(15)
		EndDate = GetDateStr(0)
	}
	$("#date1").val(StartDate);
	$("#date2").val(EndDate);
})
	
</script>
